package com.fit.components;

import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.*;
import org.apache.tapestry5.BindingConstants;

import com.fit.entities.user.User;
import com.fit.pages.Index;
import com.fit.services.Authenticator;

/**
 * Layout component for pages of application Fitness.
 */
@IncludeStylesheet("context:layout/layout.css")
public class Layout
{
    /** The page title, for the <title> element and the <h1> element. */
    @Property
    @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
    private String title;

    @Property
    private String pageName;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private String sidebarTitle;

    @Property
    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private Block sidebar;

    @Inject
    private ComponentResources resources;
    
    @Inject
	private Authenticator authenticator;

    public String getClassForPageName() {
		return resources.getPageName().equalsIgnoreCase(pageName) ? "current_page_item"
				: null;
	}

	public User getUser() {
		if (authenticator.isLoggedIn()) {
			return authenticator.getLoggedUser();
		}
		return null;
	}

	public String getPrivilegeName() {
		return authenticator.getLoggedUser().getRole().toString();
	}

	@Log
	public Object onActionFromLogout() {
		authenticator.logout();
		return Index.class;
	}

    public String[] getPageNames()
    {
    	
      return new String[] { "Index", "About", "Contact"};
    }
}
